function deltr(delbtn) {
	$(delbtn).parents(".controls").remove();
}
function click_submit_code(){
	$("#div_upload_file").hide();
	$("#div_submit_code").toggle("normal");
}

function click_upload_file(){
	$("#div_upload_file").toggle("normal");
	$("#div_submit_code").hide();
}

function click_add_dependence(){
	//$("#dependModal").modal('show');
	$('#file_list').hide();
	$('#dependDlg').dialog('open');
}
function click_add_dependence_com(){
	$('#dependComDlg').dialog('open');
}
function cancel_file_list(){
	$("#search_name").val("");
	$("#file_list").hide();
}

function search_file_list(){
	var name = $("#search_name").val().trim();
	if (name == "") {
		return;
	}
	$.get('upload_file/get_by_name', {
		'name' : name
	}, function(data) {
		if (data.success == 'true') {
			$("#file_list").show();
			$("#file_list tbody").html("");
			var rows = $("<tbody></tbody>");
			$
					.each(
							data.data,
							function(n, value) {
								var tr = $("<tr></tr>");
								var selectTd = $(
										"<td id='td_uri'></td>")
										.append(
												"<input type='checkbox' id='uri' name='uri' value='"
					+ value.uri + "'>");
								var typeTd = $("<td></td>")
										.append(value.type);
								var nameTd = $("<td id='td_uri'></td>")
										.append(value.name);
								var componentTd = $("<td></td>")
										.append(value.component);
								tr.append(selectTd).append(
										typeTd).append(nameTd)
										.append(componentTd)
										.appendTo(rows);
							});
			$("#file_list tbody").html(rows.html());
		}
	}, 'json');
}

function select_files(){
	var uriArray = new Array();
	var nameArray = new Array();
	$("#file_list tbody tr").each(
			function() {
				if ($(this).children("#td_uri")
						.children("#uri").prop("checked")) {
					var uri = $(this).children("#td_uri")
							.children("#uri").val();
					var value = $(this).children("#td_uri").text();
					uriArray.push(uri);
					nameArray.push(value);
				}
			});
	for(var i = 0;i< nameArray.length;i++){
		$("#depend_list").append('<div class="controls"><input type="hidden" name="file_uri" value="'+uriArray[i]+'">'+ '<code>'
				+ nameArray[i]
				+ '</code><button style="margin-left:50px;margin-bottom:5px" type="button" class="btn" onclick="deltr(this)">删除</button></div>');
	}
	$("#search_name").val("");
	$("#dependModal").modal('hide');
}

function select_dep_coms(){
	var idArray = new Array();
	var nameArray = new Array();
	$("#com_list tbody tr").each(
			function() {
				if ($(this).children("#td_id")
						.children("#depId").prop("checked")) {
					var id = $(this).children("#td_id")
							.children("#depId").val();
					var value = $(this).children("#td_name").text();
					idArray.push(id);
					nameArray.push(value);
					$(this).children("#td_id")
					.children("#depId").attr("checked", false);
					$(this).children("#td_id")
					.children("#depId").attr("disabled", true);
				}
			});
	for(var i = 0;i< nameArray.length;i++){
		$("#depend_com_list").append('<div class="controls"><input type="hidden" name="com_id" value="'+idArray[i]+'">'+ '<code>'
				+ nameArray[i]
				+ '</code><button style="margin-left:50px;margin-bottom:5px" type="button" class="btn" onclick="deltr(this)">删除</button></div>');
	}
}

function show_add_head_file(){
	$("#head_list")
	.append(
			'<div class="controls"><input type="file" class="file-inputs" title="选择.h头文件" name="head_file" id="head_file"><button style="margin-left:50px;margin-bottom:2px" type="button" class="btn" onclick="deltr(this)">删除</button></div>');
}

function show_add_src_file(){
	$("#src_list")
	.append(
			'<div class="controls"><input type="file" class="file-inputs" title="选择.c源文件" name="src_file" id="src_file"><button style="margin-left:50px;margin-bottom:2px" type="button" class="btn" onclick="deltr(this)">删除</button></div>');
}

function valid() {
	$("#help_name").val("英文");
	$("#div_name").removeClass("control-group error");
	$("#div_name").addClass("control-group");
	var name = $("#name").val().trim();
	if (name == "") {
		$("#div_name").removeClass("control-group");
		$("#div_name").addClass("control-group error");
		document.getElementById("help_name").innerHTML = "英文,组件名称不能为空";
		return false;
	}
	var nameArray = new Array();
	nameArray.push("head_file");
	nameArray.push("src_file");
	return checkFile(nameArray);
	//return true;
}